package com.xxxx.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.xxxx.server.pojo.Employee;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.IEmployeeService;
import com.xxxx.server.service.ISalaryService;
import com.xxxx.server.vo.PageBean;
import com.xxxx.server.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * wsy 2021-11-26 16:56
 * 员工账套管理
 **/
@RestController
@RequestMapping("/salary/sobcfg")
@Api(tags = "员工账套管理")
public class SalarySobCfgController {


    @Autowired
    private ISalaryService salaryService;

    @Autowired
    private IEmployeeService iEmployeeService;

    @ApiOperation("获取所有账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries(){
        return salaryService.list();
    }

    @ApiOperation("获取所有员工的工资账套")
    @GetMapping("")
    public RespBean<PageBean> getAllEmployeeWithSalary(@RequestParam(defaultValue = "1") Integer currentPage,
                                                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageBean pageBean = iEmployeeService.getAllEmployeeWithSalary(currentPage,pageSize);
        return new RespBean<PageBean>().success("ok",pageBean);
    }

    @ApiOperation("更新员工账套")
    @PutMapping
    public RespBean updateEmpSalary(Integer eId,Integer sId){
        if (iEmployeeService.update(new UpdateWrapper<Employee>().set("salaryId",sId).eq("id",eId))){
            return new RespBean().success("更新成功");
        }
        return new RespBean().error("更新失败");
    }
}

